Connecting to an existing IPython kernel using the Qt Console¶
The Frontend/Kernel Model¶
The traditional IPython (ipython
) consists of a single process that
combines a terminal based UI with the process that runs the users code.
While this traditional application still exists, the modern Jupyter consists of two processes:
- Kernel: this is the process that runs the users code.
- Frontend: this is the process that provides the user interface where the user types code and sees results.
Jupyter currently has 3 frontends:
- Terminal Console (
jupyter console
) - Qt Console (
jupyter qtconsole
) - Notebook (
jupyter notebook
)
The Kernel and Frontend communicate over a ZeroMQ/JSON based messaging
protocol, which allows multiple Frontends (even of different types) to
communicate with a single Kernel. This opens the door for all sorts of
interesting things, such as connecting a Console or Qt Console to a
Notebook’s Kernel. For example, you may want to connect a Qt console to
your Notebook’s Kernel and use it as a help browser, calling ??
on
objects in the Qt console (whose pager is more flexible than the one in
the notebook).
This Notebook describes how you would connect another Frontend to an IPython Kernel that is associated with a Notebook. The commands currently given here are specific to the IPython kernel.
Manual connection¶
To connect another Frontend to a Kernel manually, you first need to find
out the connection information for the Kernel using the
%connect_info
magic:
In [1]:
%connect_info
{
"shell_port": 44341,
"signature_scheme": "hmac-sha256",
"stdin_port": 51398,
"ip": "127.0.0.1",
"control_port": 54343,
"transport": "tcp",
"kernel_name": "",
"iopub_port": 33086,
"key": "b46abafa-1187f6819f7cb99e5f1a485b",
"hb_port": 44851
}
Paste the above JSON into a file, and connect with:
$> jupyter <app> --existing <file>
or, if you are local, you can connect with just:
$> jupyter <app> --existing /tmp/tmp7xvdw1ow.json
or even just:
$> jupyter <app> --existing
if this is the most recent Jupyter kernel you have started.
You can see that this magic displays everything you need to connect to this Notebook’s Kernel.
Automatic connection using a new Qt Console¶
You can also start a new Qt Console connected to your current Kernel by
using the %qtconsole
magic. This will detect the necessary
connection information and start the Qt Console for you automatically.
In [2]:
a = 10
In [3]:
%qtconsole